package com.fr.cell.core.date;

import com.fr.base.FRContext;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;

public class SingleObjectComboBoxModel extends AbstractListModel
  implements ComboBoxModel
{
  private SimpleDateFormat dateFormat;
  private String selectedDate = "";

  public SingleObjectComboBoxModel()
  {
  }

  public SingleObjectComboBoxModel(SimpleDateFormat paramSimpleDateFormat)
  {
    setDateFormat(paramSimpleDateFormat);
  }

  public void setDateFormat(SimpleDateFormat paramSimpleDateFormat)
  {
    this.dateFormat = paramSimpleDateFormat;
  }

  public SimpleDateFormat getDateFormat()
  {
    return this.dateFormat;
  }

  public void setSelectedItem(Object paramObject)
  {
    if (paramObject == null)
      return;
    if (paramObject instanceof Date)
      try
      {
        this.selectedDate = this.dateFormat.format((Date)paramObject);
      }
      catch (Exception localException1)
      {
        FRContext.getLogger().log(Level.WARNING, localException1.getMessage(), localException1);
      }
    else
      try
      {
        String str1 = paramObject.toString().trim();
        if ((str1.length() != 10) && (str1.length() != 19))
          return;
        String str2 = this.dateFormat.toPattern();
        if ((str1.length() == 10) && (str2.length() == 19))
          str1 = str1 + this.selectedDate.substring(10);
        this.dateFormat.parse(str1);
        this.selectedDate = str1;
      }
      catch (Exception localException2)
      {
        throw new UnsupportedOperationException("Invalid datetime: string [" + paramObject + "], format is [" + this.dateFormat.toPattern() + "]. ");
      }
    fireContentsChanged(this, -1, -1);
  }

  public Object getSelectedItem()
  {
    return this.selectedDate;
  }

  public Object getElementAt(int paramInt)
  {
    return this.selectedDate;
  }

  public int getSize()
  {
    return 1;
  }
}